﻿<DockPanel x:Class="DevControlLibrary.UI.TableDefinitionControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300" 
           xmlns:local="clr-namespace:DevControlLibrary.UI"
           xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"
           xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
           xmlns:BaseControlLibrary="clr-namespace:BaseControlLibrary;assembly=BaseControlLibrary">
    <DockPanel.Resources>
        <BaseControlLibrary:ImageConverter x:Key="UrlConverter"/>
        <local:ColorConvert x:Key="colorConvert"/>
        <ContextMenu x:Key="menu">
            <MenuItem Header="设置为主键" Click="MenuItem_Click"/>
        </ContextMenu>
    </DockPanel.Resources>
    <Grid>
        <dxg:GridControl  Name="gridControl1" ContextMenu="{StaticResource menu}">
            <dxg:GridControl.Resources>
                <ControlTemplate x:Key="displayTemplate">
                    <Border Background="{Binding Converter={StaticResource colorConvert}}">
                        <TextBlock VerticalAlignment="Center" HorizontalAlignment="Left" Padding="4,0,0,0"  Text="{Binding Value}"/>
                    </Border>
                </ControlTemplate>
                <ControlTemplate x:Key="checkDisplayTemplate">
                    <Border Background="{Binding Converter={StaticResource colorConvert}}">
                        <CheckBox VerticalContentAlignment="Center" HorizontalAlignment="Center" Margin="4,0,0,0"  IsChecked="{Binding Value}"/>
                    </Border>
                </ControlTemplate>
            </dxg:GridControl.Resources>
            <dxg:GridControl.Columns>
                <dxg:GridColumn FieldName="ImageUrl" Width="16" AllowEditing="False">
                    <dxg:GridColumn.CellTemplate>
                        <DataTemplate>
                            <Image  Width="16" Source="{Binding Path=Value,Converter={StaticResource UrlConverter}}"/>
                        </DataTemplate>
                    </dxg:GridColumn.CellTemplate>
                </dxg:GridColumn>
                <dxg:GridColumn FieldName="ColumnName" Header="列名" DisplayTemplate="{StaticResource displayTemplate}"/>
                <dxg:GridColumn FieldName="TypeName" Header="数据类型"  DisplayTemplate="{StaticResource displayTemplate}">
                    <dxg:GridColumn.EditSettings>
                        <dxe:ComboBoxEditSettings AutoComplete="True" Name="CbType"/>
                    </dxg:GridColumn.EditSettings>
                </dxg:GridColumn>
                <dxg:GridColumn FieldName="LengthString" Header="长度" DisplayTemplate="{StaticResource displayTemplate}"/>
                <dxg:GridColumn FieldName="IsNull" Header="允许为空" DisplayTemplate="{StaticResource checkDisplayTemplate}">
                    <dxg:GridColumn.EditSettings>
                        <dxe:CheckEditSettings  />
                    </dxg:GridColumn.EditSettings>
                </dxg:GridColumn>
                <dxg:GridColumn FieldName="DefaultValue" Header="默认值"   DisplayTemplate="{StaticResource displayTemplate}"/>
                <dxg:GridColumn FieldName="Status" Header="状态" AllowEditing="False"/>
            </dxg:GridControl.Columns>
            <dxg:GridControl.View>
                <dxg:TableView Name="view" ShowAutoFilterRow="True" ShowGroupPanel="False"  MultiSelectMode="Row" WaitIndicatorType="Panel" NewItemRowPosition="Top" CellValueChanged="view_CellValueChanged" />
            </dxg:GridControl.View>
        </dxg:GridControl>
    </Grid>
</DockPanel>
